package com.yanqu.road.dataHelper.action.del;

import com.yanqu.road.dataHelper.gameServer.GameServer;
import com.yanqu.road.dataHelper.manager.DataMgr;
import com.yanqu.road.dataHelper.repair.BaseRepair;
import com.yanqu.road.utils.string.StringUtils;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

/**
 * 删除过期的数据
 * @Author xx
 * @Date 2020/11/11
 */
public class delOutOfDateData extends BaseRepair {

    public delOutOfDateData(GameServer gameServer) {
        super(gameServer);
    }

    @Override
    public void repair(long param1, String param2) {

    }

    public void go(List<Integer> activityIdList){
        if(activityIdList.size() != 0){
            int activityConditionDelCount = delActivityCondition(activityIdList);
            DataMgr.addTextLine("删除活动条件数据t_u_activity_condition-"+activityConditionDelCount);

        }
    }

    private int delActivityCondition(List<Integer> activityIdList) {
        ResultSet rs = null;
        CallableStatement call = null;
        String sql = "DELETE FROM t_u_activity_condition WHERE activityId in(" + StringUtils.listToString(activityIdList, ",") + ")";
        try {
            call = getGameServer().getConnection().prepareCall(sql);
            rs = call.executeQuery();
            return call.executeUpdate();
        } catch (SQLException ex) {
            getGameServer().getLogger().error("异常错误", ex);
        } finally {
            getGameServer().closeConnection(call, rs);
        }
        return 0;
    }

}
